package com.xoa.controller.knowledge;

import com.xoa.model.knowledge.ClumnTree;
import com.xoa.model.knowledge.KnowledgeDocfile;
import com.xoa.service.knowledge.KnowlidgeService;
import com.xoa.util.LimsJson;
import com.xoa.util.common.DataTree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author: ZhuYize
 * @Date: 2020/9/12 15:18
 * @Description: 知识管理公用控制器
 */
@Controller
@RequestMapping("knowledge")
public class KnowledgeController {

    @Autowired
    private KnowlidgeService knowlidgeService;


    @RequestMapping("/knowledgeIndex")
    public String getKnowledgePage() { return "/app/knowledge/knowledge"; }

    //跳转客户下载界面
    @RequestMapping("/download")
    public String downloadIndex() { return "/app/knowledge/clientManager/clientDownload"; }
    //跳转查询文档类别界面
    @RequestMapping("/selectType")
    public String selectType() { return "/app/knowledge/clientManager/selectType"; }

//    //跳转下载界面 ，注释掉原因：另做登录接口不安全，最后使用oa登录
//    @RequestMapping("/download")
//    public String getDownPage(Model model,HttpServletRequest request) {
//        Object o = request.getSession().getAttribute("cust");
//        if(o==null){ //如果当前session没有登录信息就返回登录页面,这里不判断过期问题，就算登录进去，点击下载还需要判断过期和权限
//            model.addAttribute("LogoImg", "/xs?com/xoa/knowledge/logoEPM.png");
//            //LogoImg
//            return "/app/knowledge/knowledgeLogin";
//        }else{
//            return "/app/knowledge/download";
//        }
//    }

//    //跳转登录界面 ，注释掉原因：另做登录接口不安全，最后使用oa登录
//    @RequestMapping("/knowledgeLogin")
//    public String getKnowledgeLogin() { return "/app/knowledge/knowledgeLogin"; }

//    //登录 ，注释掉原因：另做登录接口不安全，最后使用oa登录
//    @RequestMapping("/loging")
//    @ResponseBody
//    public LimsJson loging(HttpServletRequest request,String account,String password) {
//        return knowlidgeService.loging(request,account,password);
//    }



    /**
     * @Author: ZhuYize
     * @Date: 2020/9/12 16:25
     * @param: parentColumnId 父id
     * @Description: 获取栏目分类
     */
    @RequestMapping("/getKnowledgeType")
    @ResponseBody
    public LimsJson getKnowledgeType(Integer parentColumnId,String colunmType) {
        return knowlidgeService.getKnowledgeType(parentColumnId,colunmType);
    }

    /**
     * 根据SysCode查询文档类别
     * @param codeNo
     * @return
     */
    @RequestMapping("/getKnowledgeTypeByCode")
    @ResponseBody
    public LimsJson getKnowledgeTypeByCode(String codeNo) {
        return knowlidgeService.getKnowledgeTypeByCode(codeNo);
    }

    /**
     * 根据columnId查询栏目
     * @return
     */
    @RequestMapping("/getColumnById")
    @ResponseBody
    public LimsJson getColumnById(String columnIds) {
        return knowlidgeService.getColumnById(columnIds);
    }


    /**
     * @Author: ZhuYize
     * @Date: 2020/9/12 17:20
     * @Description: 删除栏目类型
     * @param: columnIds 栏目类型id串
     * @return: LimsJson
     */
    @RequestMapping("/delKnowledgeType")
    @ResponseBody
    public LimsJson delKnowledgeType(String columnIds) {

        return knowlidgeService.delKnowledgeType(columnIds);
    }

    /**
     * 获取栏目类型，标签页数据源
     * @param request
     * @return
     * 查询sys_code中的PARENT_NO=KNOWLEDGE_COLUMN_TYPE（知识栏目类别）
     */
    @RequestMapping("/getColumnTag")
    @ResponseBody
    public LimsJson getColumnTag(HttpServletRequest request) {
        return knowlidgeService.getColumnTag(request);
    }


    @RequestMapping("/childTree")
    @ResponseBody
    public LimsJson childTree(HttpServletRequest request, String codeNo) {
        return knowlidgeService.childTree(request,codeNo);
    }

    @RequestMapping(value="/down",produces = {"application/json;charset=UTF-8"})
    public String download(HttpServletRequest request, HttpServletResponse response,Integer docId) {
        knowlidgeService.download(request,response,docId);
        return null;
    }

    @RequestMapping("/lookFile")
    @ResponseBody
    public LimsJson lookFile(HttpServletRequest request,Integer docId) {
        return knowlidgeService.lookFile(request,docId);
    }

    @RequestMapping("/getCurrentPriv")
    @ResponseBody
    public LimsJson getCurrentPriv(HttpServletRequest request, KnowledgeDocfile docfile, Integer page, Integer limit) {
        return knowlidgeService.getCurrentPriv(request,docfile,page,limit);
    }

    /**
     * 退出登录 ，注释掉原因：另做登录接口不安全，最后使用oa登录
     * @param request
     * @return
     */
//    @RequestMapping("/logout")
//    @ResponseBody
//    public LimsJson logout(HttpServletRequest request) {
//        request.getSession().removeAttribute("cust");
//        LimsJson limsJson = new LimsJson();
//        limsJson.setCode(0);
//        return limsJson;
//    }

    /**
     * 根据当前登录人查询知识库客户，获取客户栏目类型权限
     * @param request
     * @return
     */
    @RequestMapping("/getCustomerTree")
    @ResponseBody
    public LimsJson getCustomerTree(HttpServletRequest request) {
        return knowlidgeService.getCustomerTree(request);
    }
}
